package com.servlet.user;

import com.service.user.UserService;
import com.service.user.UserServiceImpl;
import com.util.Info;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class RegServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String Ac = req.getParameter("userName");
        String Psw = req.getParameter("password");
        String Name = req.getParameter("name");
        String Sex = req.getParameter("sex");
        String Birth = req.getParameter("birth");
        UserService userService = new UserServiceImpl();
        int n = userService.res(Ac,Psw,Name,Sex,Birth);
        if(n==1){
            resp.sendRedirect("login.jsp");
        }else{
            req.setAttribute("error","注册信息有误！");
            req.getRequestDispatcher("reg.jsp").forward(req,resp);
        }
    }
}
